<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="消息名称" prop="flwNoticeContent">
        <el-input
          v-model="queryParams.flwNoticeContent"
          placeholder="请输入消息名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!-- <el-form-item label="任务状态" prop="isDone">
        <el-select
          v-model="queryParams.isDone"
          placeholder="任务状态"
          clearable
          style="width: 240px"
        >
          <el-option label="已完成" value="1" />
          <el-option label="未完成" value="0" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="提醒日期" prop="dateRange">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="allRead"
         >标记已读</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table fit v-loading="loading" border :data="dataList">
      <el-table-column label="序号" type="index" width="120" />
      <el-table-column
        label="消息名称"
        prop="flwNoticeContent"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <el-link type="primary" @click="handleDetail(scope.row)">{{
            scope.row.noticeContent
          }}</el-link>
        </template>
      </el-table-column>

      <el-table-column label="提醒时间" prop="createTime" />
      <!-- <el-table-column label="状态" align="center" width="100">
        <template slot-scope="scope">
          {{ scope.row.isDone === 1 ? "已完成" : "未完成" }}
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      @close="getList"
      title="审核记录"
      :visible.sync="auditLogShow"
      width="50%"
      append-to-body
    >
      <el-table fit :data="logList">
        <el-table-column
          label="操作描述"
          min-width="150"
          prop="optDesc"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="操作类型"
          min-width="150"
          prop="optType"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <el-tag
              :type="
                scope.row.optType == 1
                  ? 'success'
                  : scope.row.optType == 2
                  ? 'danger'
                  : 'warning'
              "
            >
              {{
                scope.row.optType == 1
                  ? "通过"
                  : scope.row.optType == 2
                  ? "驳回"
                  : "撤销"
              }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
          min-width="150"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.sys_file_record_status_history"
              :value="scope.row.optStatus"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="理由"
          min-width="150"
          prop="reason"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="创建者"
          min-width="150"
          prop="createByName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="创建时间"
          min-width="150"
          prop="createTime"
          :show-overflow-tooltip="true"
        />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleView">查看</el-button>

        <el-button @click="handleCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { flwNoticeList,allRead } from "@/api/system/message.js";
import { querySelf } from "@/api/finance/personnel/file.js";
import { OptAuditList } from "@/api/system/fileManagerRecord.js";
import { mapState, mapMutations, mapActions } from 'vuex';
export default {
  name: "Message",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      dataList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,

      // 日期范围
      dateRange: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        flwNoticeContent: undefined,
        startCreateTime: undefined,
        endCreateTime: undefined,
        isDone: "",
      },
      current: {},
      auditLogShow: false,
      logList: [],
    };
  },
  created() {
    if (this.$route.query.isDone) {
      this.queryParams.isDone = this.$route.query.isDone;
    }
    this.getList();
  },
  methods: {
    allRead() {
      allRead().then(res => {
        if (res.code == 200) {
          // this.$router.go(-1)
          this.$store.dispatch('countAll');
        }
      })
    },
    handleCancel() {
      this.$store.dispatch("GetflwNoticeCount");
      this.$store.dispatch("GettodoCount");
      this.auditLogShow = false;
    },
    handleView() {
      if (this.current.type == 3) {
        this.$router.push("/setup/file/fileHistory");
      } else if (this.current.type == 4) {
        this.$router.push("/setup/standard/history");
      }
      this.handleCancel();
    },
    handleLog(row, type) {
      OptAuditList({ busType: type, busId: row.busId }).then((res) => {
        this.logList = res.data;
        this.auditLogShow = true;
      });
    },
    handleDetail(row) {
      this.current = row;
      return
      if (row.type == 1) {
        this.querySelf();
      } else if (row.type == 2) {
        this.$router.push("/setup/certificate?isEdit=true&id=" + row.busId);
      } else if (row.type == 3) {
        this.handleLog(row, 1);
        //3-文件申请
      } else if (row.type == 4) {
        this.handleLog(row, 2);
        // 4 - 标准申请;
      }else if(row.type == 8) {
         this.$router.push("/setup/supplier/addSupplier?isEdit=true&id="  + row.busId);
      }else if(row.type == 9) {
         this.$router.push("/setup/2/addProject?isEdit=true&id="  + row.busId);
      }
    },
    querySelf() {
      querySelf().then((res) => {
        if (res.data) {
          this.$router.push(
            "/setup/user/fileInfo?isInfo=true&id=" + res.data.userDocBaseId
          );
        } else {
          this.$message.warning("暂无档案");
        }
      });
    },
    jump(row) {
      //已完成-我的流程
      this.$router.push({
        path: "/workflow/process/detail/" + row.procInsId,
        query: {
          definitionId: row.procDefId,
          deployId: row.deployId,
          taskId: row.taskId,
          id: row.busId,
          finished: !row.isDone,
        },
      });
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      flwNoticeList(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startCreateTime",
          "endCreateTime"
        )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");

      this.queryParams.isDone = "";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.roleId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.roleId || this.ids;
      this.$modal
        .confirm('是否确认删除角色编号为"' + roleIds + '"的数据项？')
        .then(function () {
          return delRole(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
